Option Explicit On
Imports System.Text.RegularExpressions
Imports system
Imports System.IO
Module ModuloEDI
    Public VD4908Message As Array
    Dim lista As ArrayList
    Structure MyStructure
        Public Data As Date
        Public Peca As String
        Public quantidade As Integer
    End Structure
    Public Fitem As MyStructure
    Public VD4908Lines As Integer
    Public t As Integer
    Public Sub LoadTextFile()
        Dim sourceFile As String = M_800.dir_all
        If File.Exists(sourceFile) Then
            VD4908Message = File.ReadAllLines(sourceFile)
            VD4908Lines = VD4908Message.GetUpperBound(t)
        End If
        ciclo4908()
    End Sub
    Private Sub Pc821(ByVal str821 As String)
        M_800.x814 = 0
        Dim versao As String
        Dim fornecedor, cliente, data_transmit, nr_contrib_Cliente, nr_contrib_Fornecedor, Comercial_nr As String
        Dim nr_transmit_novo, nr_transmit_antigo As Single
        versao = str821.Substring(3, 2)
        cliente = str821.Substring(5, 9).Trim
        M_800.CUST_CODE = cliente
        If M_800.CUST_CODE = "" Then M_800.CUST_CODE = "43"
        fornecedor = CStr(str821.Substring(14, 9).Trim)
        M_800.SUPP_CODE = fornecedor
        If M_800.SUPP_CODE = "5099100" Then M_800.SUPP_CODE = "50991"
        nr_transmit_antigo = CSng(str821.Substring(23, 5).Trim)
        M_800.TRANS_OLD = nr_transmit_antigo
        nr_transmit_novo = CSng(str821.Substring(28, 5).Trim)
        M_800.TRANS_NEW = nr_transmit_novo
        data_transmit = "20" & (str821.Substring(33, 6)).Trim
        M_800.TRANS_DATE = data_transmit
        nr_contrib_Cliente = (str821.Substring(39, 20)).Trim
        M_800.CUST_VAT = nr_contrib_Cliente
        nr_contrib_Fornecedor = (str821.Substring(59, 20)).Trim
        M_800.SUPP_VAT = nr_contrib_Fornecedor
        Comercial_nr = (str821.Substring(79, 25)).Trim ' Comercial ID(Mandatory in some european countries - Spain, Belgium)
        M_800.comerc_nr = Comercial_nr
        '************************************************** Making File CSV *********************************
        M_800.X = My.Settings.SendTo & M_800.supplier & "4908" & Mid(My.Forms.Form1.TextBox2.Text, Len(M_800.supplier) + 6) & ".csv"
        If File.Exists(M_800.X) Then
            MsgBox("File Already exists in the directory. Please remove or rename it.", MsgBoxStyle.OkOnly)
            End
        Else
            Dim fs As New FileStream(M_800.X, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
            fs.Close()
        End If
        '************************************************** End ******************************************
        '********************************************** Save Line 821 ***************************************
        M_800.i = M_800.i + 10000
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine(M_800.supplier & " SBI" & ";" & "" & ";" & "Client:" & ";" & M_800.CUST_CODE & ";" & "Supplier:" & ";" & M_800.SUPP_CODE)
        newline.WriteLine("" & ";" & "" & ";" & "Old Transmission:" & ";" & nr_transmit_antigo & ";" & "New Transmission:" & ";" & nr_transmit_novo & ";" & "Transmission Date:" & ";" & Mid(data_transmit, 1, 4) & "/" & Mid(data_transmit, 5, 2) & "/" & Mid(data_transmit, 7, 2))
        newline.WriteLine("" & ";" & "" & ";" & "Client VAT:" & ";" & M_800.CUST_VAT & ";" & "Supplier VAT:" & ";" & M_800.SUPP_VAT & ";" & "Comercial Nr:" & ";" & M_800.comerc_nr)
        newline.Close()
        '************************************************** End ******************************************
    End Sub
    Private Sub Pc822(ByVal str822 As String)
        Dim versao As String
        Dim nr_nota_credito, data_nota_credito, data_pagamento As String
        Dim descontos, soma_descontos As Double
        Dim sinal_cod1, sinal_cod2 As Integer ' 1 --> "+", 2 --> "-"
        Dim Soma_IVA As Double
        Dim Total_nota_credito As Double
        Dim moeda As String
        Dim identificador_entrega, pais As String
        Dim cod_nota_credito As Integer  ' cod_nota_credito = 0 --> credit note, 1 --> balancing invoice, 2 --> unassessed receipt os goods
        Dim nr_departamento_contab As String

        versao = str822.Substring(3, 2)
        nr_nota_credito = str822.Substring(5, 8).Trim
        M_800.SBI_NUMBER = nr_nota_credito
        data_nota_credito = "20" & (str822.Substring(13, 2)).Trim & "/" & (str822.Substring(15, 2)).Trim & "/" & (str822.Substring(17, 2)).Trim
        M_800.SBI_DATE = data_nota_credito
        data_pagamento = "20" & (str822.Substring(19, 2)).Trim & "/" & (str822.Substring(21, 2)).Trim & "/" & (str822.Substring(23, 2)).Trim
        M_800.SBI_PAYDUEDATE = data_pagamento
        descontos = CDbl(str822.Substring(25, 13).Trim) / 100
        M_800.Disc = descontos
        sinal_cod1 = CInt(str822.Substring(38, 1).Trim) ' if 1 --> "+" if 2 --> "-"
        If sinal_cod1 = 1 Then
            M_800.sinal1 = "+"
        Else
            M_800.sinal1 = "-"
        End If
        soma_descontos = CDbl(str822.Substring(39, 13).Trim) / 100
        M_800.DISC_AMOUNT = soma_descontos
        Soma_IVA = CDbl(str822.Substring(52, 13).Trim) / 100
        M_800.TOTAL_VAT = Soma_IVA
        Total_nota_credito = CDbl(str822.Substring(65, 13).Trim) / 100
        M_800.TOTAL_SBI_VAL = Total_nota_credito
        sinal_cod2 = CInt(str822.Substring(78, 1).Trim) ' if 1 --> "+" if 2 --> "-"
        If sinal_cod2 = 1 Then
            M_800.sinal2 = "+"
        Else
            M_800.sinal2 = "-"
        End If
        moeda = str822.Substring(79, 3).Trim
        M_800.CURRENCY_CODE = moeda
        identificador_entrega = str822.Substring(82, 14).Trim
        M_800.ID_entrega = identificador_entrega
        cod_nota_credito = CInt(str822.Substring(96, 1).Trim)
        Select Case cod_nota_credito
            Case 0
                M_800.TYPE_SUPP = "credit note"
            Case 1
                M_800.TYPE_SUPP = "balancing invoice"
            Case 2
                M_800.TYPE_SUPP = "unassessed receipt os goods"
            Case Else
                M_800.TYPE_SUPP = ""
        End Select
        pais = str822.Substring(97, 2).Trim
        M_800.COUNTRY_CD_CUST = pais
        nr_departamento_contab = str822.Substring(99, 8).Trim
        M_800.Account_Dep_Nr = nr_departamento_contab

        ''*********************** Save Line 822 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine()
        newline.WriteLine("Credit Note Nr:" & ";" & M_800.SBI_NUMBER & ";" & "Credit Note Date:" & ";" & M_800.SBI_DATE & ";" & "Payment Date:" & ";" & M_800.SBI_PAYDUEDATE & ";" & "Discounts:" & ";" & M_800.Disc & ";" & "Signal Code 1:" & ";" & M_800.sinal1 & ";" & "Discounts Sum:" & ";" & M_800.DISC_AMOUNT & ";" & "VAT Sum:" & ";" & M_800.TOTAL_VAT & ";" & "Credit Note Ammount:" & ";" & M_800.TOTAL_SBI_VAL & ";" & "Signal Code 2:" & ";" & M_800.sinal2 & ";" & "Currency:" & ";" & M_800.CURRENCY_CODE & ";" & "Delivery ID:" & ";" & M_800.ID_entrega & ";" & "Credit Note Code:" & ";" & M_800.TYPE_SUPP & ";" & "Country:" & ";" & M_800.COUNTRY_CD_CUST & ";" & "Account Department Nr:" & ";" & M_800.Account_Dep_Nr)
        newline.Close()
        ''**************************** End ********************************
    End Sub

    Private Sub pc823(ByVal str823 As String)

        Dim versao As String
        Dim guia_remessa As String
        Dim fabrica_cliente As String
        Dim data_envio As String
        Dim soma_cobrancas, soma_descontos As Double
        Dim sinal_cod1, sinal_cod2 As Integer ' 1 --> "+", 2 --> "-"
        Dim Soma_IVA As Double
        Dim Total_guia_remessa As Double
        Dim PN_contratado, local_descarga, ligacao_entre_docs As String
        Dim data_entrega, contacto_cliente As String

        versao = str823.Substring(3, 2)
        guia_remessa = str823.Substring(5, 8).Trim
        fabrica_cliente = str823.Substring(13, 3).Trim
        data_envio = "20" & (str823.Substring(16, 2)).Trim & "/" & (str823.Substring(18, 2)).Trim & "/" & (str823.Substring(20, 2)).Trim
        soma_cobrancas = CDbl(str823.Substring(22, 13).Trim) / 100
        sinal_cod1 = CInt(str823.Substring(35, 1).Trim) ' if 1 --> + if 2  --> -
        If sinal_cod1 = 1 Then
            M_800.sinal1_2 = "+"
        Else
            M_800.sinal1_2 = "-"
        End If
        soma_descontos = CDbl(str823.Substring(36, 13).Trim) / 100
        Soma_IVA = CDbl(str823.Substring(49, 13).Trim) / 100
        Total_guia_remessa = CDbl(str823.Substring(62, 13).Trim) / 100
        sinal_cod2 = CInt(str823.Substring(75, 1).Trim) ' if 1 --> + if 2 --> -
        If sinal_cod2 = 1 Then
            M_800.sinal2_2 = "+"
        Else
            M_800.sinal2_2 = "-"
        End If
        PN_contratado = str823.Substring(76, 12).Trim
        local_descarga = str823.Substring(88, 5).Trim
        ligacao_entre_docs = str823.Substring(93, 8).Trim
        data_entrega = "20" & (str823.Substring(101, 2)).Trim & "/" & (str823.Substring(103, 2)).Trim & "/" & (str823.Substring(105, 2)).Trim
        contacto_cliente = CStr(str823.Substring(107, 15).Trim)
        M_800.Contacto_cliente = "'" & contacto_cliente

        '*********************** Save Line 823 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine("Delivery Note" & ";" & guia_remessa & ";" & "Client Factory" & ";" & fabrica_cliente & ";" & "Shipping Date" & ";" & data_envio & ";" & "Collect Sum" & ";" & soma_cobrancas & ";" & "Signal Code 1" & ";" & M_800.sinal1_2 & ";" & "Discounts Sum" & ";" & soma_descontos & ";" & "VAT Sum" & ";" & Soma_IVA & ";" & "Delivery Note Value" & ";" & Total_guia_remessa & ";" & "Signal Code 2" & ";" & M_800.sinal2_2 & ";" & "Hired PN" & ";" & PN_contratado & ";" & "Delivery Local" & ";" & local_descarga & ";" & "Docs Connection" & ";" & ligacao_entre_docs & ";" & "Delivery Date" & ";" & data_entrega & ";" & "Client Contact" & ";" & M_800.Contacto_cliente)
        newline.WriteLine("PN" & ";" & "Quantity" & ";" & "Unit" & ";" & "Price per unit" & ";" & "Net price per unit" & ";" & "Total price" & ";" & "Signal" & ";" & "Discount (%)" & ";" & "Total discount" & ";" & "VAT TAX" & ";" & "Total VAT" & ";" & "Test Nr")
        newline.Close()
        '*************************** End **********************************
    End Sub

    Private Sub pc824(ByVal str824 As String)

        Dim versao As String
        Dim cod_transaccao As Integer
        Dim PN_Cliente As String
        Dim unidade As String ' UNIT: PCE - piece, KGM - kilogram, MTR - metre, LTR - litre, NPR - pair
        Dim quantidade As Double
        Dim cod_unidade_preco As Integer ' 01 - per 1 unit, 02 - per 100 units, 03 - per 1000 units, 99 - per quantity indicated
        Dim preco_liquido_por_unidade As Double
        Dim preco_total As Double ' with discounts
        Dim cod_sinal As Integer ' if 1 -> + () if 2  -> - (debit to supplier)
        Dim percent_desconto As Double
        Dim valor_desconto As Double
        Dim taxa_IVA As Double
        Dim valor_IVA As Double ' not discounted
        Dim nr_teste As String

        versao = str824.Substring(3, 2)
        cod_transaccao = CInt(str824.Substring(5, 2).Trim)
        PN_Cliente = str824.Substring(7, 22).Trim
        quantidade = CDbl(str824.Substring(29, 13).Trim) / 1000
        Select Case str824.Substring(42, 3).Trim
            Case Is = "PCE"
                unidade = "Piece"
            Case Is = "KGM"
                unidade = "Kilogram"
            Case Is = "MTR"
                unidade = "Metre"
            Case Is = "LTR"
                unidade = "Litre"
            Case Is = "NPR"
                unidade = "Pair"
            Case Else
                unidade = str824.Substring(42, 3).Trim
        End Select
        cod_unidade_preco = CInt(str824.Substring(45, 2).Trim)
        Select Case cod_unidade_preco
            Case Is = 1
                M_800.cod_uni_p = "per 1 unit"
                preco_liquido_por_unidade = CDbl(str824.Substring(47, 13).Trim) / 100
            Case Is = 2
                M_800.cod_uni_p = "per 100 unit"
                preco_liquido_por_unidade = CDbl(str824.Substring(47, 13).Trim) / 10000
            Case Is = 3
                M_800.cod_uni_p = "per 1000 unit"
                preco_liquido_por_unidade = CDbl(str824.Substring(47, 13).Trim) / 100000
            Case Is = 99
                M_800.cod_uni_p = "per 1 unit"
                preco_liquido_por_unidade = CDbl(str824.Substring(47, 13).Trim) / 100
            Case Else
                preco_liquido_por_unidade = CDbl(str824.Substring(47, 13).Trim)
        End Select
        preco_total = CDbl(str824.Substring(60, 13).Trim) / 100
        cod_sinal = CInt(str824.Substring(73, 1).Trim)
        If cod_sinal = 1 Then
            M_800.sinal1_3 = "+"
        Else
            M_800.sinal1_3 = "-"
        End If
        percent_desconto = CDbl(str824.Substring(74, 3).Trim) / 100
        valor_desconto = CDbl(str824.Substring(77, 13).Trim) / 100
        taxa_IVA = CDbl(str824.Substring(90, 4).Trim) / 100
        valor_IVA = CDbl(str824.Substring(94, 13).Trim) / 100
        nr_teste = str824.Substring(107, 14).Trim

        '************************** Save Line 824 ********************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine(PN_Cliente & ";" & quantidade & ";" & unidade & ";" & cod_unidade_preco & ";" & preco_liquido_por_unidade & ";" & preco_total & ";" & M_800.sinal1_3 & ";" & percent_desconto & ";" & valor_desconto & ";" & taxa_IVA & ";" & valor_IVA & ";" & nr_teste)
        newline.Close()
        '******************************* End **************************************
    End Sub

    Private Sub pc825(ByVal str825 As String)
        Dim versao As String
        Dim cod_desconto As String ' 01 - packaging, 02 - freight, 03 - material price increase surcharge (MTZ), 99 - other
        Dim valor_desconto As Double
        Dim cod_sinal As Integer ' if 1 -> + () if 2  -> - (Supplier debit)
        versao = str825.Substring(3, 2)
        Select Case str825.Substring(5, 2).Trim
            Case Is = "01"
                cod_desconto = "packaging"
            Case Is = "02"
                cod_desconto = "freight"
            Case Is = "03"
                cod_desconto = "material price increase surcharge (MTZ)"
            Case Is = "99"
                cod_desconto = "other"
            Case Else
                cod_desconto = str825.Substring(5, 2).Trim
        End Select
        valor_desconto = CDbl(str825.Substring(7, 13).Trim) / 100
        cod_sinal = CInt(str825.Substring(20, 1).Trim)
        If cod_sinal = 1 Then
            M_800.sinal1_4 = "+"
        Else
            M_800.sinal1_4 = "-"
        End If

        '*********************** Save Line 825 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine("Discount Code:" & ";" & cod_desconto & ";" & "Discount Value:" & ";" & valor_desconto & ";" & "Signal:" & ";" & M_800.sinal1_4)
        newline.Close()
        '*********************** End ****************************
    End Sub

    Private Sub pc826(ByVal str826 As String)
        Dim versao As String
        Dim cod_unidade_preco As String ' 01 - per 1 unit, 02 - per 100 units, 03 - per 1000 units, 99 - per quantity indicated
        Dim preco_novo As Double
        Dim data_valida_preco_novo As String
        Dim dif_preco As Double ' between old and new price
        Dim cod_sinal As Integer ' if 1 --> +  if 2 --> - (supplier debit)
        versao = str826.Substring(3, 2)
        Select Case str826.Substring(5, 2).Trim
            Case Is = "01"
                cod_unidade_preco = "per 1 unit"
            Case Is = "02"
                cod_unidade_preco = "per 100 units"
            Case Is = "03"
                cod_unidade_preco = "per 1000 units"
            Case Is = "99"
                cod_unidade_preco = "per indicated quantity"
            Case Else
                cod_unidade_preco = str826.Substring(5, 2).Trim
        End Select
        preco_novo = CDbl(str826.Substring(7, 13).Trim) / 100
        data_valida_preco_novo = "20" & (str826.Substring(20, 6)).Trim
        dif_preco = CDbl(str826.Substring(26, 13).Trim) / 100
        cod_sinal = CInt(str826.Substring(39, 1).Trim)
        If cod_sinal = 1 Then
            M_800.sinal1_5 = "+"
        Else
            M_800.sinal1_5 = "-"
        End If

        '*********************** Save Line 826 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        'newline.WriteLine("Codigo_Linha" & ";" & "cod_unidade_preco" & ";" & "preco_novo" & ";" & "data_valida_preco_novo" & ";" & "dif_preco" & ";" & "cod_sinal")
        newline.WriteLine("Unit Price Code:" & ";" & cod_unidade_preco & ";" & "New Price:" & ";" & preco_novo & ";" & "New Price Valid Date:" & ";" & data_valida_preco_novo & ";" & "Price Diference:" & ";" & dif_preco & ";" & "Signal:" & ";" & M_800.sinal1_5)
        newline.Close()
        '*********************** End ****************************
    End Sub

    Private Sub pc827(ByVal str827 As String)
        Dim versao, text1, text2, text3 As String

        versao = str827.Substring(3, 2)
        text1 = str827.Substring(5, 40)
        text2 = str827.Substring(45, 40)
        text3 = str827.Substring(85, 40)

        '*********************** Save Line 827 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine("Text1:" & ";" & text1 & ";" & "Text2:" & ";" & text2 & ";" & "Text3:" & ";" & text3)
        newline.Close()
        '*********************** FIM ****************************
    End Sub

    Private Sub pc828(ByVal str828 As String)
        Dim versao, moeda As String
        Dim taxa As Double
        Dim data_taxa As String
        Dim valor_total_final_inclui_IVA As Double ' 0 - credit note, 1 - balancing invoice, 2 - unassessed receipt os goods
        Dim valor_total_final_sem_IVA As Double
        Dim valor_total_IVA As Double

        versao = str828.Substring(3, 2)
        moeda = str828.Substring(5, 3).Trim
        taxa = CDbl(str828.Substring(8, 17).Trim) / 100000000000
        data_taxa = "20" & (str828.Substring(25, 6)).Trim
        valor_total_final_inclui_IVA = CDbl(str828.Substring(31, 13).Trim)
        valor_total_final_sem_IVA = CDbl(str828.Substring(44, 13).Trim)
        valor_total_IVA = CDbl(str828.Substring(57, 13).Trim)

        '*********************** Save Line 828 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine("Currency" & ";" & "TAX" & ";" & "TAX Date" & ";" & "Final Value With VAT" & ";" & "Final Value Without VAT" & ";" & "VAT Value")
        newline.WriteLine(moeda & ";" & taxa & ";" & data_taxa & ";" & valor_total_final_inclui_IVA & ";" & valor_total_final_sem_IVA & ";" & valor_total_IVA)
        newline.Close()
        '*********************** End ****************************
    End Sub

    Private Sub Pc829(ByVal str829 As String)
        Dim versao As String
        Dim contador821, contador822, contador823, contador824, contador825, contador826, contador827, contador828, contador829 As Integer
        Dim Valor_IVA As Double
        Dim valor_total_guias_remessa As Double
        Dim cod_sinal As Integer ' if 1 -> "+" if 2  -> "-" 
        Dim modo_pagamento As Integer ' 0 - Undefined, 1 - check, 2 - bank transfer, 3 - bill of exchange, 4 - check/bill of exchange, 5 - settlement debtors, 6 - electronic transfer

        versao = str829.Substring(3, 2)
        contador821 = CInt(str829.Substring(5, 7))  ' count 821
        contador822 = CInt(str829.Substring(12, 7)) ' count 822
        contador823 = CInt(str829.Substring(19, 7)) ' count 823
        contador824 = CInt(str829.Substring(26, 7)) ' count 824
        contador825 = CInt(str829.Substring(33, 7)) ' count 825
        contador826 = CInt(str829.Substring(40, 7)) ' count 826
        contador827 = CInt(str829.Substring(47, 7)) ' count 827
        contador829 = CInt(str829.Substring(54, 7)) ' count 828
        contador828 = CInt(str829.Substring(61, 7)) ' count 829
        Valor_IVA = CDbl(str829.Substring(68, 13)) / 1000000000
        valor_total_guias_remessa = CDbl(str829.Substring(81, 13)) / 100
        M_800.line = str829.Substring(0, 96).Trim
        If CStr(str829.Substring(94, 1).Trim) <> "" Then
            cod_sinal = CInt(str829.Substring(94, 1).Trim)
            If cod_sinal = 1 Then
                M_800.sinal1_6 = "+"
            Else
                M_800.sinal1_6 = "-"
            End If
        Else
            M_800.sinal1_6 = ""
        End If
        If CStr(str829.Substring(95, 1).Trim) <> "" Then
            modo_pagamento = CInt(CStr(str829.Substring(95, 1).Trim))
            Select Case modo_pagamento
                Case 0
                    M_800.modo_paga = CStr("Undefined")
                Case 1
                    M_800.modo_paga = CStr("check")
                Case 2
                    M_800.modo_paga = CStr("bank transfer")
                Case 3
                    M_800.modo_paga = CStr("bill of exchange")
                Case 4
                    M_800.modo_paga = CStr("check/bill of exchange")
                Case 5
                    M_800.modo_paga = CStr("settlement debtors")
                Case 6
                    M_800.modo_paga = CStr("electronic transfer")
                Case Else
                    M_800.modo_paga = CStr("")
            End Select
        Else
            M_800.modo_paga = CStr("")
        End If
        '*********************** Save Line 829 ****************************
        Dim newline As IO.StreamWriter
        newline = New IO.StreamWriter(M_800.X, True)
        newline.WriteLine("count821" & ";" & "count822" & ";" & "count823" & ";" & "count824" & ";" & "count825" & ";" & "count826" & ";" & "count827" & ";" & "count828" & ";" & "count829" & ";" & "VAT" & ";" & "Delivery Notes Final Value" & ";" & "Signal" & ";" & "Pay mode")
        newline.WriteLine(contador821 & ";" & contador822 & ";" & contador823 & ";" & contador824 & ";" & contador825 & ";" & contador826 & ";" & contador827 & ";" & contador828 & ";" & contador829 & ";" & Valor_IVA & ";" & valor_total_guias_remessa & ";" & M_800.sinal1_6 & ";" & M_800.modo_paga)
        newline.Close()
        '*********************** End ****************************

    End Sub

    Private Sub ciclo4908()

        For t = 0 To VD4908Lines

            Select Case Left(CStr(VD4908Message.GetValue(t)), 3)
                Case CStr(821)
                    Pc821(CStr(VD4908Message.GetValue(t)))
                Case CStr(822)
                    Pc822(CStr(VD4908Message.GetValue(t)))
                Case CStr(823)
                    pc823(CStr(VD4908Message.GetValue(t)))
                Case CStr(824)
                    pc824(CStr(VD4908Message.GetValue(t)))
                Case CStr(825)
                    pc825(CStr(VD4908Message.GetValue(t)))
                Case CStr(826)
                    pc826(CStr(VD4908Message.GetValue(t)))
                Case CStr(827)
                    pc827(CStr(VD4908Message.GetValue(t)))
                Case CStr(828)
                    pc828(CStr(VD4908Message.GetValue(t)))
                Case CStr(829)
                    Pc829(CStr(VD4908Message.GetValue(t)))
            End Select
        Next

    End Sub
End Module
